package com.my.feign.config;

import com.my.feign.config.fallBack.XcloudFeign;
import com.netflix.hystrix.HystrixCommand;
import feign.Feign;
import feign.hystrix.HystrixFeign;
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import org.springframework.context.annotation.Primary;
import org.springframework.context.annotation.Scope;

@Configuration
@ConditionalOnClass({HystrixCommand.class, HystrixFeign.class})
public class HystrixFeignConfiguration {
    /*https://www.jianshu.com/p/68d1fadb9e85*/
    /*
    全局的自定义降级配置
    @FeignClient(value = "CLOUD-PAYMENT-SERVICE")
    没有设置的情况fallback fallbackFactory
    */
    @Bean
    @Primary
    @Scope("prototype")
    @ConditionalOnProperty(name = "feign.hystrix.enabled", havingValue = "true")
    public Feign.Builder xcloudFeignHystrixBuilder() {
        return XcloudFeign.builder();
    }
}